package com.play.ballen.home.ui

import android.content.Context
import android.content.Intent
import android.view.View
import com.hjq.toast.ToastUtils
import com.play.ballen.R
import com.play.ballen.databinding.ActivityServiceBinding
import com.play.ballen.home.vm.ServiceVM
import com.yuven.appframework.base.BaseStdTitleActivity
import com.yuven.appframework.util.ClipboardUtils
import com.yuven.appframework.util.imageloader.ImageUtil
import com.yuven.appframework.util.setOnSingleClickListener
import com.yuven.baselib.utils.ResourceUtil
import com.yuven.baselib.utils.ViewUtils

class ServiceActivity : BaseStdTitleActivity<ServiceVM, ActivityServiceBinding>() {

    companion object {
        @JvmStatic
        fun start(context: Context) {
            val starter = Intent(context, ServiceActivity::class.java)
            context.startActivity(starter)
        }
    }

    override fun viewModelClass(): Class<ServiceVM> {
        return ServiceVM::class.java
    }

    override fun contentLayoutId(): Int {
        return R.layout.activity_service
    }

    override fun initObserver() {
        super.initObserver()

        viewModel.serviceInfo.observe(this) {
            it.run {
                dataBinding.tvTwitter.text = service_twitter
                dataBinding.tvTelegram.text = service_telegram
            }
        }
    }

    private val onClickListener = tag@{ v: View ->
        if (viewModel.serviceInfo.value == null) {
            return@tag
        }

        when (v.id) {
            R.id.tvTwitter -> {
                ClipboardUtils.setText(viewModel.serviceInfo.value!!.service_twitter, this)
                ToastUtils.show(ResourceUtil.getString(R.string.me_copy))
            }

            R.id.tvTelegram -> {
                ClipboardUtils.setText(viewModel.serviceInfo.value!!.service_telegram, this)
                ToastUtils.show(ResourceUtil.getString(R.string.me_copy))
            }
        }
    }

    override fun initData() {
        viewModel.service()

        dataBinding.tvTelegram.setOnSingleClickListener(onClickListener)
        dataBinding.tvTwitter.setOnSingleClickListener(onClickListener)
    }

    override fun initIntent(intent: Intent?) {
    }

    override fun initView() {
        super.initView()

    }

    override fun getToolBarTitle(): String = ResourceUtil.getString(R.string.service_title)
}